using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApiClient;
using WebApiClient.Contexts;

namespace ConsoleApp
{
    public class RequestGlobalFilter : IApiActionFilter
    {
        public Task OnBeginRequestAsync(ApiActionContext context)
        {
            if (!context.RequestMessage.Headers.Contains("Authorization")
            && !string.IsNullOrEmpty(ServiceConsts.Token))
            {
                context.RequestMessage.Headers.Add("Authorization", string.Format("Bearer {0}", ServiceConsts.Token));
            }
            // do something
            return Task.CompletedTask;
        }

        public Task OnEndRequestAsync(ApiActionContext context)
        {
            // do something
            return Task.CompletedTask;
        }
    }
}
